<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>视频观看</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/dplayer/1.25.0/DPlayer.min.css">
    <script src="https://cdn.staticfile.org/hls.js/8.0.0-beta.3/hls.min.js"></script>
    <script src="https://cdn.staticfile.org/dplayer/1.25.0/DPlayer.min.js"></script>
    <script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
</head>

<style>
    .video {
        margin-top: 20px;
        height: 55%;
        width: auto;
    }
</style>
<body>
<div id="video-name" style="text-align: center; margin-top: 50px;">标题</div>
<div>
    <div class="player video" id="player">视频播放</div>
</div>
</body>

<script>
    //const baseUrl = "http://192.168.0.149:8080";
    const baseUrl = window.location.protocol + "//" + window.location.host + "/videourl";

    function getQueryVariable(variable) {
        let query = window.location.search.substring(1);
        let vars = query.split("&");
        for (var i = 0; i < vars.length; i++) {
            var pair = vars[i].split("=");
            if (pair[0] === variable) {
                return pair[1];
            }
        }
        return "";
    }

    let data = {
        url: "https://video.jializyw.com:8800/20200714/8ePgbAI8/index.m3u8",
        pic: "http://tp.jializyw.com/upload/vod/20200719-1/a0ea1ece3c5e85a3933c605264f42514.jpg"
    };

    $(function () {
        let video_id = getQueryVariable("v");
        console.log(video_id);
        if (video_id === undefined || video_id === "" || video_id === '') {
            alert("参数id为空");
            return;
        }
        let sessionId = window.localStorage.getItem("sessionKey");
        if (sessionId === null || sessionId === "") {
            alert("小伙子不要尝试外门邪道...");
            return;
        }
        let checkFlag = false;
        let checkUrl = baseUrl + "/photowall/check/sessionId?sessionId=" + sessionId;
        $.get(checkUrl, function (res) {
            if (res.code === "200" && res.data) {
                checkFlag = res.data;
                let url = baseUrl + "/photowall/query/video/" + video_id;
                $.get(url, function (res) {
                    console.log(res.data);
                    if (res.code === "200") {
                        $("#video-name").text(res.data.videoName);
                        let num = '100';
                        let dp = new DPlayer({
                            element: document.getElementById('player'),
                            autoplay: true,
                            video: {
                                url: res.data.videoUrl,
                                pic: res.data.videoPicUrl
                            },
                            highlight: [
                                {
                                    time: num === 0 ? 60 : 0,
                                    text: '次数用完只能播放60秒',
                                },
                            ],
                        });

                    }
                }, 'json');
            } else {
                alert("小伙子不要尝试外门邪道...");
            }
        });
    });
</script>
</html>
